home *** CD-ROM | disk | FTP | other *** search
/ IRIX Installation Tools & Overlays 2002 November / SGI IRIX Installation Tools & Overlays 2002 November - Disc 4.iso / dist / cluster_admin.idb / usr / cluster / bin / cdbRestore.z / cdbRestore
Text File  |  2002-10-15  |  7KB  |  197 lines

  1. #!/bin/ksh
  2. #                                                                         
  3. #  Copyright (C) 1998, Silicon Graphics, Inc.                             
  4. #  All Rights Reserved.                                                   
  5. #                                                                         
  6. #  UNPUBLISHED -- Rights reserved under the copyright laws of the United  
  7. #  States.  Use of a copyright notice is precautionary only and does not  
  8. #  imply publication or disclosure.                                       
  9. #                                                                         
  10. #  THIS SOFTWARE CONTAINS CONFIDENTIAL AND PROPRIETARY INFORMATION OF     
  11. #  SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, DISTRIBUTION, OR 
  12. #  DISCLOSURE IS STRICTLY PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN    
  13. #  PERMISSION OF SILICON GRAPHICS, INC.                                   
  14. #                                                                         
  15. #  U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND                               
  16. #  Use, duplication or disclosure by the Government is subject to         
  17. #  restrictions as set forth in FAR 52.227.19(c)(2) or subparagraph       
  18. #  (c)(1)(ii) of the Rights in Technical Data and Computer Software       
  19. #  clause at DFARS 252.227-7013 and/or in similar or successor clauses    
  20. #  in the FAR, or the DOD or NASA FAR Supplement.  Unpublished-- rights   
  21. #  reserved under the copyright laws of the United States.                
  22. #  Contractor/manufacturer is Silicon Graphics, Inc.,                     
  23. #  2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.                 
  24. #
  25. #
  26. # cdbRestore - This script restore cdb from a cdb backup file taken using
  27. #              cdbBackup script. See comments on USAGE below for details.
  28. #
  29.  
  30. SCRIPT_NAME=`/usr/bin/basename $0`
  31.  
  32. #
  33. # The usage string for this script.
  34. #
  35. # The user has to provide the cdb backup file name using option -f from which
  36. # the cdb is to be restored. By default the cdb is restored under directory
  37. # /var/cluster/cdb as /var/cluster/cdb/cdb.db and /var/cluster/cdb/cdb.db#/*.
  38. # If the cdb backup file is not a full path name and is not a relative path of
  39. # the form aa/bb/<cdb backup file>, then it is assumed that cdb backup file
  40. # is present in the default backup directory /var/cluster/cdb-backup. The user
  41. # can specify a different backup directory using the -d option.
  42. #
  43. # If the user wants the cdb to be retored under a different directory, user
  44. # can provide the full path of the expected cdb header file using the -c
  45. # option. The basename of the cdb header file should be the same as the
  46. # basename of the cdb header file saved in the cdb backup file. Normally, the
  47. # basename for the cdb header file is cdb.db.
  48. # e.g.
  49. #    /tmp/cdb/cdb.db
  50. #
  51. USAGESTR="Usage: $SCRIPT_NAME -f backup_filename [-d backup_directory] [-c CDB_header_file]"
  52.  
  53. #
  54. # DEFAULT values for various variables used in this script
  55. #
  56. # BACKUP_FILE_NAME - User supplied. The name of the cdb backup file.
  57. BACKUP_FILE_NAME=""
  58.  
  59. # BACKUP_DIR - The directory under which the cdb backup file is present.
  60. BACKUP_DIR=/var/cluster/cdb-backup
  61.  
  62. # CDB_HEADER_FILE - The cdb header file.
  63. CDB_HEADER_FILE=/var/cluster/cdb/cdb.db
  64.  
  65.  
  66.  
  67. #############
  68. # FUNCTIONS #
  69. #############
  70.  
  71. #
  72. # signal_handler():
  73. #       Arguments: None
  74. #       Return value: None
  75. #       Description:
  76. #               Invoked when user interrupts the script using signal 2 (SIGTERM)
  77. #        Removes the partially restored cdb and exits.
  78. #
  79.  
  80. function signal_handler
  81. {
  82.     echo -n "<<interrupted>> cleaning up..."
  83.     rm -f ${CDB_DIR}/${CDB_HEADER_FILE}
  84.     rm -rf ${CDB_DIR}/${CDB_DATA_ROOT_DIR}
  85.     echo "done."
  86.  
  87.         exit 1
  88. }
  89.  
  90.  
  91.  
  92. ################
  93. # MAIN PROGRAM #
  94. ################
  95.  
  96.  
  97.  
  98. #
  99. # Process the command line arguments
  100. #
  101. while getopts f:d:c:h  option
  102. do
  103.         case $option in
  104.                 f)              BACKUP_FILE_NAME=$OPTARG;;
  105.                 d)              BACKUP_DIR=$OPTARG;;
  106.                 c)              CDB_HEADER_FILE=$OPTARG;;
  107.                 h | \?)         echo $USAGESTR
  108.                 exit 1;;
  109.         esac
  110.  
  111. done
  112.  
  113. # Confirm that the user provided the backup file name. If not print usage
  114. # and exit.
  115. if [ "a$BACKUP_FILE_NAME" = "a" ]; then
  116.     echo "Error: $USAGESTR"
  117.     exit 1
  118.     
  119. fi
  120.  
  121. # If backup file name is not full path and it is not of the form aa/bb
  122. # and backup directory BACKUP_DIR is not "" then prepend BACKUP_DIR to it.
  123.  
  124. # If BACKUP_FILE_NAME is not full path
  125. echo $BACKUP_FILE_NAME | grep "^/" > /dev/null 2>&1
  126. if [ $? -ne 0 ]; then
  127.  
  128.     # If BACKUP_FILE_NAME is not of the form aa/bb
  129.     echo $BACKUP_FILE_NAME | grep "/" > /dev/null 2>&1
  130.     if [ $? -ne 0 ]; then
  131.  
  132.         # If BACKUP_DIR is not ""
  133.         if [ "a$BACKUP_DIR" != "a" ]; then
  134.  
  135.             # Prepend BACKUP_DIR to BACKUP_FILE_NAME
  136.             BACKUP_FILE_NAME=${BACKUP_DIR}/${BACKUP_FILE_NAME}
  137.  
  138.         fi
  139.     fi
  140.  
  141. fi
  142.  
  143. # Confirm that backup file exists.
  144. if [ ! -a "${BACKUP_FILE_NAME}" ]; then
  145.     echo "Error: $SCRIPT_NAME: File ${BACKUP_FILE_NAME} does not exist."
  146.     exit 1
  147. fi
  148.  
  149. # Get the cdb parent directory name CDB_DIR from cdb header file name
  150. CDB_DIR=`dirname $CDB_HEADER_FILE`
  151.  
  152. # Confirm that cdb parent directory exists
  153. if [ ! -d "$CDB_DIR" ] || [ ! -w "$CDB_DIR" ]; then
  154.     echo "Error: $SCRIPT_NAME: CDB directory $CDB_DIR doesn't exist"
  155.     exit 1
  156. fi
  157.  
  158. # Confirm that cdb header file does not exist.
  159. if [ -a "$CDB_HEADER_FILE" ]; then
  160.         echo "Error: $SCRIPT_NAME: Database header file $CDB_HEADER_FILE already exists."
  161.         exit 1
  162. fi
  163.  
  164. # Get the cdb data directory name from the cdb header file name
  165. CDB_DATA_ROOT_DIR=${CDB_HEADER_FILE}"#"
  166.  
  167. # Confirm that cdb data directory does not exist.
  168. if [ -a "$CDB_DATA_ROOT_DIR" ]; then
  169.     echo "Error: $SCRIPT_NAME: Database data directory $CDB_DATA_ROOT_DIR already exists."
  170.     exit 1
  171. fi
  172.  
  173. # Extract the basenames for cdb header file and cdb data directory.
  174. # This information will be needed when extracting files from the cdb dump file.
  175. CDB_HEADER_FILE=`basename $CDB_HEADER_FILE`
  176. CDB_DATA_ROOT_DIR=`basename $CDB_DATA_ROOT_DIR`
  177.  
  178. # Added for debugging
  179. #echo "BACKUP_FILE_NAME        = $BACKUP_FILE_NAME"
  180. #echo "CDB_DIR                 = $CDB_DIR"
  181. #echo "CDB_HEADER_FILE         = $CDB_HEADER_FILE"
  182. #echo "CDB_DATA_ROOT_DIR       = $CDB_DATA_ROOT_DIR"
  183.  
  184. # Extract the cdb files from the user supplied cdb dump.
  185. # When interrupted by user, remove cdb header file and cdb data directory
  186. # and exit.
  187. trap signal_handler  2
  188.  
  189. echo -n "Installing cdb files from cdb backup file ${BACKUP_FILE_NAME} "
  190. echo -n "under directory ${CDB_DIR} ..."
  191. cat ${BACKUP_FILE_NAME} | /usr/bsd/uncompress | ( cd $CDB_DIR; tar xf - $CDB_HEADER_FILE $CDB_DATA_ROOT_DIR)
  192. echo "done."
  193.  
  194.  
  195. exit 0
  196.  
  197.